/*
 * 文件名：SupplierDaoImpl.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：wuliquan
 * 修改时间：2013-2-21
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.consumables.supplier.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wootide.cms.common.QueryResults;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.consumables.supplier.dao.SupplierInfoDao;
import com.wootide.cms.service.consumables.supplier.pojo.SupplierInfo;

/**
 * 
 * 供应商数据访问层接口实现
 * 〈功能详细描述〉
 * @author wuliquan
 * @version 2013-2-21
 * @see SupplierInfoDaoImpl
 * @since
 */
public class SupplierInfoDaoImpl extends HibernateDaoSupport implements SupplierInfoDao
{
    /**
     * 运行日志
     */
    private RunLog runLog;
    
    public int findNumBySupplierName(String supplierName)
    {
        runLog.debug("supplierName=" + supplierName);
        
        return ((Number)getHibernateTemplate().findByNamedQuery("findSupplierInfoNumByName",
                supplierName)
                .get(0)).intValue();
    }
    
    @SuppressWarnings("unchecked")
    public SupplierInfo findOneSupplierByName(String supplierName)
    {
        runLog.debug("supplierName=" + supplierName);
        List<SupplierInfo> list = getHibernateTemplate().findByNamedQuery("findOneSupplierByName",supplierName);
        
        return list.isEmpty() ? null : (SupplierInfo)list.get(0);
    }
    
    public SupplierInfo findOneSupplierBySupplierId(Integer supplierId)
    {
        runLog.debug("supplierId=" + supplierId);
        
        return getHibernateTemplate().get(SupplierInfo.class, supplierId);
    }
    
    public QueryResults findAllSuppliers()
    {
        QueryResults queryResults = new QueryResults();
        queryResults.setResults(getHibernateTemplate().findByNamedQuery("findSuppliers"));
        return queryResults;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }
    
}
